package top.huhuiyu.teachproject.vo;

import lombok.Data;
import top.huhuiyu.teachproject.entity.TbRole;
import top.huhuiyu.teachproject.entity.TbUser;
import top.huhuiyu.teachproject.entity.TbUserInfo;

/**
 * 用户视图信息
 *
 * @author 胡辉煜
 */
@Data
public class UserInfo {

  private TbUser tbUser;
  private TbUserInfo tbUserInfo;
  private TbRole tbRole;

  public UserInfo processViewData() {
    UserInfo info = new UserInfo();
    // 基本用户信息
    if (this.tbUser != null) {
      TbUser user = new TbUser();
      user.setUid(tbUser.getUid());
      user.setUsername(tbUser.getUsername());
      user.setRole(tbUser.getRole());
      user.setLastupdate(tbUser.getLastupdate());
      info.setTbUser(user);
    }
    // 附加用户信息
    if (tbUserInfo != null) {
      TbUserInfo userInfo = new TbUserInfo();
      userInfo.setNickname(tbUserInfo.getNickname());
      userInfo.setSex(tbUserInfo.getSex());
      userInfo.setEmail(tbUserInfo.getEmail());
      userInfo.setPhone(tbUserInfo.getPhone());
      userInfo.setQq(tbUserInfo.getQq());
      userInfo.setWechat(tbUserInfo.getWechat());
      userInfo.setImg(tbUserInfo.getImg());
      userInfo.setInfo(tbUserInfo.getInfo());
      userInfo.setLastupdate(tbUserInfo.getLastupdate());
      info.setTbUserInfo(userInfo);
    }
    // 角色信息
    if (this.tbRole != null) {
      TbRole role = new TbRole();
      role.setRoleName(tbRole.getRoleName());
      info.setTbRole(role);
    }
    return info;
  }
}
